import {Map,List,fromJS} from 'immutable';

export default (state = Map(), action) => {

  // console.log('111',Map(action.info).toJS())

  if (action.type === 'exam_list') {
    state = state.clear();
    return state.set('examlist',List(action.examlist));
  }

  if (action.type === 'exam_detail') {
    return state.set('examdetail',Map(action.info));
  }

  if (action.type === 'exam_edit') {
    return state.merge({
      examdetail : Map(action.info)
    });
  }

  if (action.type === 'exam_delete') {
    return state.update('examlist',value=>{
      return value.delete(action.index)
    });
  }

  if (action.type === 'room_list') {
    return state.set('roomlist',List(action.info));
  }

  if (action.type === 'room_add') {
    return state.update('roomlist',value=>{
      return value.push(action.info)
    });
  }

  if (action.type === 'room_edit') {
    return state.update('roomlist',value=>{
      return value.update(action.index,value=>{
        return action.info
      })
    });
  }

  if (action.type === 'room_delete') {
    return state.update('roomlist',value=>{
      return value.delete(action.index)
    });
  }

  if (action.type === 'question_list') {
    return state.merge({
      questionList : List(action.info)
    })
  }
  if (action.type === 'question_upload_list') {
    return state.merge({
      questionPath : action.questionPath || '',
      questionList : List(action.info)
    })
  }

  if (action.type === 'question_items') {
    return state.merge({
      questionItems : List(action.info)
    })
  }

  if (action.type === 'user_list') {
    return state.merge({
      userPath : action.userPath || '',
      userList : List(action.info)
    })
  }

  return state;
};